package cn.com.homeyoda.aimate.aihealth.ui.my.family.manage;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wzq.mvvmsmart.utils.GlideLoadUtils;
import com.wzq.mvvmsmart.utils.TimeUtils;
import com.wzq.mvvmsmart.utils.constant.TimeConstants;

import java.util.ArrayList;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.bean.FamilyMembersBean;
import cn.com.homeyoda.aimate.aihealth.bean.MultipleItem;
import cn.com.homeyoda.aimate.aihealth.utils.StringUtils;

public class ManageAdapter extends BaseMultiItemQuickAdapter<MultipleItem<Object>, BaseViewHolder> {

    public ManageAdapter() {
        super(new ArrayList<>());
        // 绑定类型与布局ID
        addItemType(MultipleItem.MEMBER, R.layout.member_item);
        addItemType(MultipleItem.ADD, R.layout.member_add_item);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, MultipleItem item) {
        if (holder.getItemViewType() == MultipleItem.MEMBER) {
            FamilyMembersBean.DataBean.FamilyMembers member = (FamilyMembersBean.DataBean.FamilyMembers) item.getData();
            GlideLoadUtils.loadImg(holder.getView(R.id.iv_member_avatar), member.getAvatar(), R.mipmap.ic_member1);
            holder.setGone(R.id.tv_admin, holder.getAdapterPosition() == 0);
            holder.setText(R.id.tv_member_name, StringUtils.removeAllBank(member.getName()));
            long age = TimeUtils.getTimeSpanByNow(member.getBirthday() + " 00:00:00", TimeConstants.DAY) / 365;
            holder.setText(R.id.tv_member_age, Math.abs(age) + "岁");
            holder.setText(R.id.tv_member_gender, member.getSex() == 1 ? "男" : "女");
        } else if (holder.getItemViewType() == MultipleItem.ADD) {
            holder.setText(R.id.tv_add_member_title, mContext.getString(Integer.parseInt(item.getData().toString())));
        }
    }
}
